const jwt = require('jsonwebtoken')
const config  = require("../config")
// 创建token
exports.createToken = function(req){
    return new Promise((resolve,rejece) => {
        const token = jwt.sign({
            user_id: req.id
        }, config.secretKey, { expiresIn: config.expireTime });
        resolve(token);
    })
}
// 验证token
exports.verToken = function(token){
   
    
    return new Promise((resolve,rejece) => {
        try {
            var decoded = jwt.verify(token,config.secretKey);
            resolve(decoded);
          } catch (e) {
            
            rejece (e)
          }
        
    })
}